#! /bin/sh

fail() {
	echo "$@" 1>&2
	exit 1
}

window() {
	local action=${1:-add}
	local iter=${2:-1}
	local delta=${3:-1}
	local event=node_${action}
	local instance_name=${INSTANCE_NAME:-test}
	local class_name=${CLASS_NAME:-Test}

	local cmd
	case "$action" in
		add) cmd="./test_window $instance_name $class_name" ;;
		remove) cmd="bspc node -c" ;;
	esac
	while [ $iter -gt 0 ] ; do
		local rsp_chan=$(bspc subscribe -f -c "$delta" "$event")
		$cmd &
		cat "$rsp_chan" > /dev/null
		iter=$((iter - 1))
	done
}
